/** 
 * File-Name:FileUtils.java
 *
 * Created on 2011-7-16 上午07:20:07
 * 
 * @author: Neo (neolimeng@gmail.com)
 * Software Engineering Institute, Peking University, China
 * 
 * Copyright (c) 2009, Peking University
 * 
 *
 */
package neoutil;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;

/**
 * Description:
 * 
 * @author: Neo (neolimeng@gmail.com) Software Engineering Institute, Peking
 *          University, China
 * @version 1.0 2011-7-16 上午07:20:07
 */
public class FileUtils {

	public static void copy(File src, File dst) {
		try {
			FileOutputStream fos = null;
			FileInputStream fis = null;
			try {
				fis = new FileInputStream(src);
				fos = new FileOutputStream(dst);
				byte[] buffer = new byte[1024];
				int len = 0;
				while ((len = fis.read(buffer)) > 0) {
					fos.write(buffer, 0, len);
				}

				System.out.println("Copy file from " + src.getName() + " to "
						+ dst.getName());
			} catch (Exception e) {
				e.printStackTrace();
			} finally {
				if (null != fis) {
					fis.close();
				}
				if (null != fos) {
					fos.close();
				}
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	public static String getExtention(String fileName) {
		int pos = fileName.lastIndexOf(".");
		return fileName.substring(pos);
	}

	public static String getValidFileName(String originalFileName) {
		return originalFileName.replace("!,@,#,$,%,^,&,*,~,", "_");
	}

	public static void main(String[] args) {

	}

}
